package bb.action;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Component;
import org.springframework.stereotype.Controller;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;

import bb.entity.Product;
import bb.service.ProductService;
import io.vertx.ext.web.RoutingContext;

@Controller
public class ProductAction {
	
	@Resource
	private ProductService productService;


	public void queryProduct(RoutingContext ctx) {
		
		List<Product> list = productService.getAllProducts();
		
		  ObjectMapper mapper = new ObjectMapper();
		  try {
			String str = mapper.writeValueAsString(list);
			ctx.response().putHeader("content-type", "text/html;charset=UTF-8").end("product:" +str);

		} catch (JsonProcessingException e) {
			e.printStackTrace();
		}
	}

}
